package com.wcq.studentbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wcq.studentbackend.dto.StudentDetailDTO;
import com.wcq.studentbackend.entity.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface StudentMapper extends BaseMapper<Student> {
    // 可以添加自定义查询方法，例如根据学号查询
    // Student findByStuNo(String stuNo);

    @Select("""
            SELECT 
                s.name, s.stu_no, s.gender, s.phone, s.create_time, 
                c.class_name AS className
            FROM 
                students s
            LEFT JOIN 
                classes c ON s.class_id = c.id
            WHERE 
                s.stu_no = #{stuNo}
            LIMIT 1
            """)
    StudentDetailDTO findDetailByStuNo(@Param("stuNo") String stuNo);
}